package cn.snsprj.authserver.controller;

import cn.snsprj.authserver.util.RedisUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author SKH
 * @date 2018-08-22 11:56
 **/
@RequestMapping("/test")
@Controller
public class TestController {


    @Autowired
    RedisUtil redisUtil;

    private Logger logger = LoggerFactory.getLogger(TestController.class);

    @RequestMapping("/redis")
    @ResponseBody
    public String testRedis(){

        String key = "name";

        String value = (String) redisUtil.get(key);

        if (StringUtils.isBlank(value)){
            redisUtil.setEx(key, "宝哥", 100);
            return "name is null";
        }else {
            return "name is " + value;
        }
    }
}
